#ifndef __FactorManagerBase_INL__
#define __FactorManagerBase_INL__

template<class ProductType, class ClassFactor>
FactorManagerBase<ProductType, ClassFactor>::FactorManagerBase(void)
{
}

template<class ProductType, class ClassFactor>
FactorManagerBase<ProductType, ClassFactor>::~FactorManagerBase(void)
{
	DeleteFactorys();
}

template<class ProductType, class ClassFactor>
void FactorManagerBase<ProductType, ClassFactor>::DeleteFactorys()
{
	std::map<ProductType, OcRxFactory<ProductType, ClassFactor>*> ::iterator itF = mFactorys.begin();
	if (itF != mFactorys.end())
  {
		for (; itF != mFactorys.end(); itF++)
    {
		OcRxFactory<ProductType, ClassFactor>* pFactory = itF->second;
      if (pFactory)
      {
        delete pFactory; pFactory = NULL;
      }
    }

		mFactorys.clear();
  }
}


template<class ProductType, class ClassFactor>
BOOL FactorManagerBase<ProductType, ClassFactor>::RegisitFactory(ProductType type, OcRxFactory<ProductType, ClassFactor> *pclass, bool blnChange /*= true*/)
{

  BOOL blnReturn = FALSE;

  std::map<ProductType, OcRxFactory<ProductType, ClassFactor>*> ::iterator it = mFactorys.find(type);
  if (it == mFactorys.end())
  {
    if (pclass !=NULL)
    {
		mFactorys[type] = pclass;

      blnReturn = TRUE;
    }
  }
  else
  {

  }

  if (pclass)
  {
    pclass->mType = type;
  }


  if (blnChange && blnReturn)
  {
    mFactory = pclass;
  }

  return blnReturn;
}


template<class ProductType, class ClassFactor>
ClassFactor * FactorManagerBase<ProductType, ClassFactor>::_Creat(ProductType type, void* pData)
{
	ClassFactor *pClass = NULL;
	std::map<ProductType, OcRxFactory<ProductType, ClassFactor>*> ::iterator it = mFactorys.find(type);
	if (it != mFactorys.end())
  {
	  OcRxFactory<ProductType, ClassFactor>* pFactory = it->second;
    if (pFactory)
    {
      pClass = pFactory->Creat(pData);
    }
  }
  return pClass;
}

template<class ProductType, class ClassFactor>
void FactorManagerBase<ProductType, ClassFactor>::destroy(ProductType type, ClassFactor *Obj, void* pData)
{
  if (Obj)
  {
	  std::map<ProductType, OcRxFactory<ProductType, ClassFactor>*> ::iterator it = mFactorys.find(type);
	  if (it != mFactorys.end())
    {
		OcRxFactory<ProductType, ClassFactor>* pFactory = it->second;
      if (pFactory)
      {
        pFactory->destroy(Obj, pData);
      }
    }
    else
    {
      if (Obj)
      {
        delete Obj; Obj = NULL;
      }
    }
  }
  return ;
}


#endif
